﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Interfaces;

namespace Core.Domains
{
    public class Action: IAction 
    {
        #region Private fields
        private int _actionId;
        private DateTime _dateOfAction;
        private string _organization = "";
        private List<IBuilding> _buildings;
        private bool _formDB = false;
        #endregion

        #region Public fields
        public int ActionId
        {
            get { return _actionId; }
            set { _actionId = value; }
        }

        public string Organization
        {
            get { return _organization; }
            set { _organization = value; }
        }

        public DateTime Date
        {
            get { return _dateOfAction; }
            set { _dateOfAction = value; }
        }

        public List<IBuilding> Buildings
        {
            get { return _buildings; }
            set { _buildings = value; }
        }

        #endregion
        
        #region Mhetods
        public void ConstructIt(object[] Record)
        {
            _actionId = int.Parse(Record[0].ToString());
            _organization = Record[1].ToString();
            _dateOfAction = DateTime.Parse(Record[2].ToString());
            _formDB = true;
        }

        public bool FromDatabase()
        {
            return _formDB; 
        }

        public string GetErrorByCode(int code)
        {
            if (code == 1451 || code == 547)
            {
                return "К этому аукциону привязаны здания";
            }
            return "";
        }

        #endregion

        public Action()
        {}

        public override string ToString()
        {
            return _organization + "/" + _dateOfAction;
        }
    }
}
